package com.huatai.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huatai.common.util.StringUtil;
import com.huatai.manage.entity.TbStageSubEntity;
import com.huatai.manage.entity.TbStageSubEntity;
import com.huatai.manage.mapper.TbStageSubMapper;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.service.TbStageSubService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 子阶段管理 服务实现类
 * </p>
 *
 * @author luoxc
 * @since 2023-03-22
 */
@Service
public class TbStageSubServiceImpl extends ServiceImpl<TbStageSubMapper, TbStageSubEntity> implements TbStageSubService {


	/**
	 * 分页获取子阶段列表
	 * @param pageQuery
	 * @return
	 */
	@Override
	public Page<TbStageSubEntity> pageList(PageQuery<TbStageSubEntity> pageQuery) {
		Page<TbStageSubEntity> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
		LambdaQueryWrapper<TbStageSubEntity> wrapper = Wrappers.<TbStageSubEntity>lambdaQuery();
		wrapper.like(StringUtil.isNotBlank(pageQuery.getData().getStageName()),
			TbStageSubEntity::getStageName, pageQuery.getData().getStageName());
		return this.page(page, wrapper);
	}

	/**
	 * 根据阶段id获取信息
	 * @param stageId
	 * @return
	 */
	@Override
	public TbStageSubEntity getByStageId(String stageId) {
		LambdaQueryWrapper<TbStageSubEntity> wrapper = Wrappers.<TbStageSubEntity>lambdaQuery();
		wrapper.eq(TbStageSubEntity::getStageId, stageId);
		return getOne(wrapper);
	}

	/**
	 * 根据阶段id集合删除信息
	 * @param stageIds
	 * @return
	 */
	@Override
	public boolean removes(List<String> stageIds) {
		if (stageIds.isEmpty()) return false;
		LambdaQueryWrapper<TbStageSubEntity> wrapper = Wrappers.<TbStageSubEntity>lambdaQuery();
		wrapper.in(TbStageSubEntity::getStageId, stageIds);
		return remove(wrapper);
	}

	/**
	 * 根据阶段id修改信息
	 * @param tbStageSubEntity
	 * @return
	 */
	@Override
	public boolean update(TbStageSubEntity tbStageSubEntity) {
		LambdaUpdateWrapper<TbStageSubEntity> wrapper = Wrappers.<TbStageSubEntity>lambdaUpdate();
		wrapper.eq(TbStageSubEntity::getStageId, tbStageSubEntity.getStageId());
		return update(tbStageSubEntity, wrapper);
	}
}
